package com.example.emb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.emb.entity.*;
import com.example.emb.mapper.*;
import com.example.emb.service.classService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class classServiceImpl implements classService {
    @Autowired
    ClasstableMapper classtableMapper;
    @Autowired
    ClassdtableMapper classdtableMapper;
    @Autowired
    GrouptableMapper grouptableMapper;
    @Autowired
    GroupdtableMapper groupdtableMapper;
    @Autowired
    WorktableMapper worktableMapper;
    @Autowired
    StuworktableMapper stuworktableMapper;
    @Override
    public void deleteClass(int classId) {
        // 删除班级 班级d 班级内的学生，班级学生的小组，班级学生的作业，作业的zip
        //grouptable
        QueryWrapper<Grouptable> groupQueryWrapper=new QueryWrapper<>();
        groupQueryWrapper.eq("classId",classId);
        List<Grouptable> grouptable=grouptableMapper.selectList(groupQueryWrapper);
        // groupDtable
        for(Grouptable group:grouptable){
            //删除小组详细信息
            QueryWrapper<Groupdtable> groupdQueryWrapper =new QueryWrapper<>();
            groupdQueryWrapper.eq("GroupId",group.getId());
            groupdtableMapper.delete(groupdQueryWrapper);
        }
        //classtable
        QueryWrapper<Classdtable> classdQueryWrapper=new QueryWrapper<>();
        classdQueryWrapper.eq("classId",classId);
        classdtableMapper.delete(classdQueryWrapper);

        //work /stuwork
        QueryWrapper<Worktable> workQueryWrapper=new QueryWrapper<>();
        workQueryWrapper.eq("classId",classId);
        List<Worktable> list=worktableMapper.selectList(workQueryWrapper);
        for(Worktable worktable:list){
            QueryWrapper<Stuworktable> queryWrapper=new QueryWrapper<>();
            queryWrapper.eq("workid",worktable.getId());
            stuworktableMapper.delete(queryWrapper);
            worktableMapper.deleteById(worktable.getId());
        }
    }




}
